package com.heima.controller;

import com.heima.dto.pagedto.OperationPageDto;
import com.heima.service.OperationLogService;
import com.heima.vo.PageResult;
import com.heima.vo.ResultVo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@Api(tags = "日志模块 ")
public class OperationLogController {

    private final OperationLogService operationLogService;

    /**
     * 操作日志分页查询
     * @return
     */
    @GetMapping("/monitor/operlog/list")
    public PageResult queryOperationLog(OperationPageDto dto,
                                        @RequestParam(value = "params[beginTime]",required = false) String begin,
                                        @RequestParam(value = "params[endTime]",required = false) String end){
        dto.setBeginTime(begin);
        dto.setEndTime(end);
        log.info("操作日志分页查询:{}",dto);
        PageResult vo = operationLogService.queryOperationLog(dto);
        return vo;
    }

    /**
     * 批量删除日志记录
     */
    @DeleteMapping("/monitor/operlog/{ids}")
    public ResultVo deleteLog(@PathVariable List<Integer> ids){
        log.info("批量删除日志记录");
        operationLogService.deleteLog(ids);
        return new ResultVo();
    }

    /**
     * 清空记录
     */
    @DeleteMapping("/monitor/operlog/clean")
    public ResultVo cleanLog(){
        log.info("清空记录");
        operationLogService.cleanLog();
        return new ResultVo();
    }

}
